package com.example.cart_system.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface ChartsMapper {
    //统计所有的年份
    @Select("select year(otime) as time_year from `order` where usrid = #{usrid} group by time_year;")
    public List<String> getAllYear(String usrid);
    //根据年份选择月份
    @Select("SELECT MONTH(otime) as months from `order` where usrid = #{usrid} and YEAR(otime) = #{year} GROUP BY months")
    public List<String> getMonth(String usrid, String year);
    //根据日期计算日消费量
    @Select("SELECT sum(osumprice) as '日消费量', DAY(otime) as '日期' FROM `order` WHERE usrid = #{usrid} and YEAR(otime) = #{year} and MONTH(otime) = #{month} GROUP BY DAY(otime) ORDER BY DAY(otime)")
    public List<Map<String, Object>> getSumByYearAndMonth(String usrid, String year, String month);
}
